package com.vitabuybuy.tv.ui.mine.foot.viewmodel

import androidx.lifecycle.MutableLiveData
import com.library.common.base.BaseViewModel
import com.library.common.base.MessageModel
import com.library.common.ext.rxHttpRequest
import com.library.common.net.error.msg
import com.library.common.toast.XToast
import com.vitabuybuy.tv.dto.MyFootPrintListDto
import com.vitabuybuy.tv.network.MineRepository

class FootprintViewModel : BaseViewModel() {
    val footlist = MutableLiveData<MutableList<MyFootPrintListDto>>()

    fun getFootPrintList(pageNumber: Int) {
        rxHttpRequest {
            onRequest = {
                val it = MineRepository.getFootPrint(pageNumber, 10).await()
                footlist.value = it
            }
            onError = {
                XToast.normal(it.msg)
            }
            isLoadingType = true
            isRefresh = pageNumber == 1
        }
    }

    fun deleteFootPrint(id: Int, parentPos: Int, childPos: Int) {
        rxHttpRequest {
            onRequest = {
                MineRepository.deleteFootPrint(id).await()
                defUI.msgEvent.postValue(MessageModel(1, arg1 = parentPos,arg2 = childPos))
            }
            onError = {
                XToast.normal(it.msg)
            }
            isShowDialogRequest = true
        }
    }
}
